$(function () {
    window.nodes = '';
    window.str_nodes = '';
    var setting = {
        check: {
            enable: true
        },
        data: {
            simpleData: {
                enable: true
            }
        },
        callback: {
            onCheck: onCheck
        }
    };
    $.fn.zTree.init($("#treeDemo"), setting, zNodes);
    function onCheck(e, treeId, treeNode) {
        var treeObj = $.fn.zTree.getZTreeObj("treeDemo"),
            nodes = treeObj.getCheckedNodes(true);
        //alert(nodes.length);
        //document.getElementById("role")[0].value=nodes.length;
        str_nodes = '';
        for (var i = 0; i < nodes.length; i++) {
            //alert(nodes[i].id); //获取选中节点的值
            str_nodes += nodes[i].id + ',';
        }
    }

    var rid = $('#rid').val();
    $("#accessupdate").click(function () {
        $.ajax({
            url: '/role/updateAccess',
            type: 'POST',
            data: {nodes: str_nodes, rid: rid},
            dataType: 'JSON',
            cache: false,
            success: function (json) {
                dshow(json.message);
                if (json.code == 2000) {
                    window.location.href = '/role';
                }
            }
        });
    });
    $("#accessout").click(function () {
        window.location.href = '/role';
    })
});